package cn.sumpu.app.wlcity.web.mvc.hotspring;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.sumpu.app.wlcity.biz.ContentBiz;
import cn.sumpu.app.wlcity.domain.Content;
import cn.sumpu.app.wlcity.exception.AppBusinessException;
import cn.sumpu.app.wlcity.util.Common;

@Controller
public class HotspringController {
	@Autowired
	private ContentBiz contentBiz;
	@RequestMapping(value = "/hotspring.htm")
	public String toLogin(HttpServletRequest request) {
		return "hotspring/index";
	}
	
	@RequestMapping(value = "/hot.htm")
	public String hot(Integer page,HttpServletRequest request) {
		if(page == null){
			page = 1;
		}
		try {
			String radioApp =Common.APP_SPRING;
			List<Content> hotList = contentBiz.getContentHotList(page,Common.TYPE_HOT,radioApp); 
			int size = contentBiz.getContentListCount(Common.TYPE_HOT,radioApp);
			int totalPage = (size + Common.PAGE_SIZE_HOT - 1) / Common.PAGE_SIZE_HOT;
			request.setAttribute("totalPage", totalPage);
			request.setAttribute("hotList", hotList);
			request.setAttribute("link", "hot.htm");
			request.setAttribute("currentPage", page);
		} catch (AppBusinessException e) {
			e.printStackTrace();
			return "hotspring/error";
		}
		return "hotspring/hot";
	}
	
	@RequestMapping(value = "/hotDetail.htm")
	public String hotDetail(String id,HttpServletRequest request) {
		
		try {
			Content content = contentBiz.getContentById(id);
			request.setAttribute("content", content);
		} catch (AppBusinessException e) {
			e.printStackTrace();
			return "hotspring/error";
		}
		return "hotspring/hotDetail";
	}
}
